package com.charles.seckillsystem.controller.admin;

import com.charles.seckillapi.domain.SysGood;
import com.charles.seckillcommon.core.controller.BaseController;
import com.charles.seckillcommon.core.domain.AjaxResult;
import com.charles.seckillcommon.core.domain.TableInfo;
import com.charles.seckillcommon.security.annotation.RolePermit;
import com.charles.seckillsystem.form.admin.GoodListQuerys;
import com.charles.seckillsystem.mapper.SysGoodMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/good")
public class AdminGoodController extends BaseController {
    
    @Resource
    private SysGoodMapper sysGoodMapper;

    /**
     * 产品列表
     */
    @GetMapping("getGoodTableList")
    @RolePermit(values = "admin")
    public TableInfo getGoodTableList(GoodListQuerys goodListQuerys) {
        startPage();
        return getDataTable(sysGoodMapper.queryGoodTableList(goodListQuerys));
    }

    /**
     * 获取产品
     */
    @GetMapping("/getGood/{goodId}")
    @RolePermit(values = "admin")
    public AjaxResult getGood(@PathVariable("goodId") Long goodId) {
        return AjaxResult.success(sysGoodMapper.getGood(goodId));
    }

    /**
     * 添加产品
     */
    @PostMapping("addGood")
    @RolePermit(values = "admin")
    public void addGood(@RequestBody SysGood good) {
        sysGoodMapper.addGood(good);
    }
    
    /**
     * 修改产品
     */
    @PutMapping("modifyGood")
    @RolePermit(values = "admin")
    public void modifyGood(@RequestBody SysGood good) {
        sysGoodMapper.modifyGood(good);
    }

    /**
     * 删除产品
     */
    @DeleteMapping("/deleteGood/{goodId}")
    @RolePermit(values = "admin")
    public void deleteGood(@PathVariable("goodId") Long goodId) {
        sysGoodMapper.deleteGood(goodId);
    }
}
